package QianFeng17;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Frame1 extends Frame implements Frame2.MoneyListener{

    private Label label = new Label("money: ");
    private Button btn = new Button("buy");

    public static void main(String[] args) {
        new Frame1();
    }
    public Frame1() {
        this.setBounds(400,300,600,400);
        this.setLayout(new FlowLayout());
        this.add(btn);
        this.add(label);
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new Frame2().setMoneyListener(Frame1.this);
            }
        });
        //给窗体添加关闭事件
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                super.windowClosing(e);
                System.exit(0);
            }
        });
        this.setVisible(true);
    }

    //导入接口实现金钱的设置传值
    @Override
    public void setMoney(String money) {
        label.setText(money);
    }
}
